<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLoanApplyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('loan_apply', function (Blueprint $table) {
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            $table->comment = '用户放款信息表';
            $table->increments('id');
            $table->unsignedInteger('loan_request_id')->comment('授信申请表id')->unique();
            $table->string('loan_id',100)->nullable()->comment('新流订单号')->unique();
            $table->string('sub_code',20)->default('')->comment('对应新流返回的子状态值subCode');
            $table->string('loan_sign')->default('')->comment('对应新流返回的签名sign，异常时可做校验请求数据用');
            $table->unsignedDecimal('amount',10,2)->default(0)->comment('总金额');
            $table->unsignedDecimal('arrival_account',10,2)->default(0)->comment('实际到账金额');
            $table->unsignedDecimal('pre_insurance_amt',10,2)->default(0)->comment('前置险金额');
            $table->unsignedTinyInteger('period')->default(0)->comment('分期数');
            $table->string('out_trade_id')->default('')->comment('合作方借款id');
            $table->unsignedTinyInteger('loan_status')->default(0)->comment('申请状态:0默认，1处理中，2成功，3失败，4需要换卡');
            $table->unsignedInteger('user_id')->comment('当前操作用户id');
            $table->unsignedInteger('bank_card_id')->comment('用户选择的放款银行卡id');
            $table->string('ip',40)->nullable()->comment('用户ip');
            $table->timestamp('loan_time')->nullable()->default(null)->comment('放款成功时间');
            $table->string('message')->default('')->comment('资方返回信息');
            $table->text('trans_money_list')->comment('分账明细');
            $table->unsignedDecimal('lending_rate',8,4)->default(0)->comment('贷款费率');
            $table->unsignedDecimal('insurance_rate',8,4)->default(0)->comment('前置保险费');
            $table->unsignedDecimal('month_insurance_rate',8,4)->default(0)->comment('月保险费率');
            $table->unsignedDecimal('manage_rate',8,4)->default(0)->comment('管理费率');
            $table->unsignedDecimal('repayment_rate',8,4)->default(0)->comment('提前还清手续费');
            $table->unsignedDecimal('fines_rate',8,4)->default(0)->comment('逾期罚息利率');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('loan_apply');
    }
}
